package cn.sccl.tset.annotation;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.sccl.beans.User;

/**
 * @author 饶爽
 * @time 2019年9月2日 下午9:14:48
 * @version 1.0.0
 * 注解开发测试
*/
public class AnnotationDemo {
    @Test
    public void fun1() {
        //1、创建容器对象
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        //2、向容器"要"user对象
        User user = (User) ac.getBean("user");
        //3、输出
        System.out.println(user);
    }
    @Test
    //注解@Scope(scopeName="prototype")表示多例
    public void fun2() {
        //1、创建容器对象
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        //2、向容器"要"user对象
        User user = (User) ac.getBean("user");
        User user2 = (User) ac.getBean("user");
        
        System.out.println(user==user2);
        //3、输出
        System.out.println(user);
    }
    @Test
    //测试初始化和销毁
    public void fun3() {
        //1、创建容器对象
        ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        //2、向容器"要"user对象
        User user = (User) ac.getBean("user");
        //3、输出
        System.out.println(user);
        ac.close();
    }
}
